package com.jstyle.jclifexd.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.jstyle.jclifexd.R;
import com.jstyle.jclifexd.model.Run3;
import com.jstyle.jclifexd.utils.DateUtil;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

public class RecorderAdapter extends RecyclerView.Adapter  {
    Context context;
    List<Run3> run3;
    public RecorderAdapter(Context mycontext) {
        this.context=mycontext;
    }

    public void updateData(List<Run3> list){
        this.run3=list;
        notifyDataSetChanged();
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recorder, parent, false);
        RankViewHolder rankViewHolder=new RankViewHolder(view);
        return rankViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        if(null==run3){return;}
        RankViewHolder viewholder=(RankViewHolder)viewHolder;
        if(i==0){
            viewholder.haochenji.setVisibility(View.VISIBLE);
        }else{
            viewholder.haochenji.setVisibility(View.GONE);
        }
        viewholder.recordvalue.setText(run3.get(i).getDay());
        viewholder.gongli.setText(run3.get(i).getDistance()+context.getResources().getString(R.string.Kilometre));
        viewholder.record_time.setText( DateUtil.getSecond(run3.get(i).getActiveTime()));

    }

    @Override
    public int getItemCount() {
        return null==run3?0:run3.size();
    }


    class RankViewHolder extends BaseViewHolder{
        @BindView(R.id.haochenji)
        TextView haochenji;
        @BindView(R.id.recordvalue)
        TextView recordvalue;
        @BindView(R.id.gongli)
        TextView gongli;
        @BindView(R.id.record_time)
        TextView record_time;
         RankViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
